# -*- coding: utf-8 -*-

from devicetest.api import Asserts
from devicetest.log.logger import print_info
from devicetest.aw.OpenHarmony import CommonOH, WifiHelper
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup
from aw.pom import ControlCenter


class PreTest_RK3568_Basic_Systemui_0800(TestCase, ControlCenter):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面
    # 测试步骤：
    # 进入桌面，右上角下划，点击控制中心WLAN按钮
    # 预期结果：
    # 右上角下划可正常进入控制中心，点击或重复点击WLAN有效，与设置WiFi开关同步变化

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)
        Step('预置条件2：关闭wifi')
        try:
            WifiHelper.closeWifi(self.Phone1)
        except:
            pass

    def process(self):
        Step('步骤1：右上角下划，呼出控制中心')
        CommonOH.swipe(self.Phone1, **self.pull_down)
        CommonOH.wait(self.Phone1, 1)
        Step('预期结果1：成功进入控制中心')
        CommonOH.checkIfTextExist(self.Phone1, '控制中心')
        for i in range(1, 4):
            Step('步骤2.{}：点击控制中心WLAN按钮'.format(i))
            CommonOH.click(self.Phone1, **self.wlan_switch)
            CommonOH.wait(self.Phone1, 2)
            Step('预期结果2.{}：点击WLAN有效，与设置WiFi开关同步变化'.format(i))
            WifiHelper.checkWifiState(self.Phone1, expect=(i % 2 != 0))

    def teardown(self):
        Step('收尾1：右上角上划，收回控制中心')
        CommonOH.swipe(self.Phone1, **self.pull_up)
        Step('收尾2：关闭wifi')
        WifiHelper.closeWifi(self.Phone1)
